package com.baturu.vin.hyundai.dal.dao;

import com.baturu.vin.hyundai.dto.HyundaiKiaBtrRelationEntity;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

import static com.baturu.vin.hyundai.constant.HyundaiKiaTable.T_BTR_RELATION;

public interface HyundaiKiaBtrRelationDAO {

    @Select("<script>" +
            "SELECT btrId FROM `" + T_BTR_RELATION + "` " +
            "WHERE `vehicleEpcCarTypeId` = #{relation.vehicleEpcCarTypeId} " +
            "AND `productTime` = #{relation.productTime} " +
            "AND `engineCode` = #{relation.engineCode} " +
            "AND `transmissionCode` = #{relation.transmissionCode} limit 1 " +
            "</script>")
    String queryBtrIdByRelation(@Param("relation") HyundaiKiaBtrRelationEntity relation);

    @Insert("<script>" +
            "INSERT INTO `" + T_BTR_RELATION + "` (`btrId`, `vehicleEpcCarTypeId`, `modelEpcCarTypeId`, `productTime`, `engineCode`, `transmissionCode`) VALUES " +
            "<foreach item='item' index='index' collection='relations' open='' separator=',' close=''>" +
            "(#{item.btrId}, #{item.vehicleEpcCarTypeId}, #{item.modelEpcCarTypeId}, #{item.productTime}, #{item.engineCode}, #{item.transmissionCode})" +
            "</foreach>" +
            "</script>")
    void insertNewRelation(@Param("relations") List<HyundaiKiaBtrRelationEntity> relations);
}